package moe.loliserver;

import moe.loliserver.libraries.CustomLibraries;

import static moe.loliserver.legacy.util.EulaUtil.hasAcceptedEULA;
import static moe.loliserver.legacy.util.EulaUtil.writeInfos;
import moe.loliserver.legacy.util.InstallUtils;
import moe.loliserver.legacy.util.JarLoader;
import moe.loliserver.legacy.util.JarTool;
import moe.loliserver.legacy.util.i18n.i18n;
import moe.loliserver.utils.CheckJDKVersionUtil;
import moe.loliserver.utils.LoliServerConfigUtil;
import moe.loliserver.utils.UpdateCheckerUtil;

public class LoliServerStart {

    public static String getVersion() {
        return (LoliServerStart.class.getPackage().getImplementationVersion() != null) ? LoliServerStart.class.getPackage().getImplementationVersion() : "unknown";
    }

    public static void main() throws Exception {
        String path = JarTool.getJarPath();
        if(path != null && (path.contains("+") || path.contains("!"))) {
            System.out.println("[LoliServer - ERROR] Unsupported characters have been detected in your server path. \nPlease remove + or ! in your server's folder name (in the folder which contains this character).\nPath : "+path);
            System.exit(0);
        }
        LoliServerConfigUtil.load();

        System.out.println(".____          .__  .__  _________                                \n" +
                    "|    |    ____ |  | |__|/   _____/ ______________  __ ___________ \n" +
                    "|    |   /  _ \\|  | |  |\\_____  \\_/ __ \\_  __ \\  \\/ // __ \\_  __ \\\n" +
                    "|    |__(  <_> )  |_|  |/        \\  ___/|  | \\/\\   /\\  ___/|  | \\/\n" +
                    "|_______ \\____/|____/__/_______  /\\___  >__|    \\_/  \\___  >__|   \n" +
                    "        \\/                     \\/     \\/                 \\/       " + "\n" +
                    "                             " + i18n.get("LoliServer.launch.welcomemessage") + "\n");

        new CheckJDKVersionUtil();

        CustomLibraries.loadCustomLibs();
        new JarLoader().loadJar(InstallUtils.extra);

        if (LoliServerConfigUtil.bLoli("Loli-Update.check-update", true)) {
            new UpdateCheckerUtil();
        }

        LoliServerStart.class.getClassLoader().loadClass("com.google.gson.internal.bind.TypeAdapters$EnumTypeAdapter"); //Don't remove.

        if (!hasAcceptedEULA()) {
            System.out.println(LanguagesMap.i18nGet("loli.eula"));
            Thread.sleep(5000);
            writeInfos();
        }
    }
}
